//
//  SelectionSheet.swift
//  Exchange
//
//  Created by 孟祥群 on 2018/7/23.
//  Copyright © 2018年 common. All rights reserved.
//

import UIKit

class SelectionSheet: SelectBaseSheet {
    var model: SelectionModel?
    var config:SelectionConfig?
    init(model: SheetModel, coinfig: SelectConfig, dataSource: SelectmangerDelegate) {
        super.init(model: model, coinfig: coinfig, titleArr: [], selectStr: nil, dataSource: dataSource)
        self.model = model as? SelectionModel
        self.config = coinfig as? SelectionConfig
        
        self.setUpUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func setUpUI() {
        super.setUpUI()
        
        if(config?.style == sheetStyle.selectionStyle){
            config?.viewHeight = config?.filterHeight!
            let height = (kSCREEN_HEIGHT - (config?.viewHeight)!)
            selectView.frame = CGRect(x: 0, y:height, width: kSCREEN_WIDTH, height: (config?.viewHeight)!)
            let sheetView = SheetCollectionView(config: config!,model:model!, dataSource: self.dataSource!)
            sheetView.delegate = self
            selectView.addSubview(sheetView)
            sheetView.snp.makeConstraints { (make) in
                make.top.left.right.equalToSuperview()
                make.bottom.equalToSuperview()
            }
            
        }else if (config?.style == sheetStyle.leverSelectStyle) {
            config?.viewHeight = config?.leverFliterHeight
            let height = (kSCREEN_HEIGHT - (config?.viewHeight)!)
            selectView.frame = CGRect(x: 0, y:height, width: kSCREEN_WIDTH, height: (config?.viewHeight)!)
            let sheetView = SheetCollectionView(config: config!,model:model!, dataSource: self.dataSource!)
            sheetView.delegate = self
            selectView.addSubview(sheetView)
            sheetView.snp.makeConstraints { (make) in
                make.top.left.right.equalToSuperview()
                make.bottom.equalToSuperview()
            }
            
        }
        
    }
    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */

}
extension SelectionSheet: SheetCollecDelegate {
    //Mark -- sheetCollecDelegate
    func changeHeight(selectBool:Bool,contentHeight:CGFloat) {
        selectView.layer.removeAllAnimations()
        if selectBool {
            config?.viewHeight = config?.style == .selectionStyle ? (config?.filtetOpenHeight)! + contentHeight : (config?.leverFliterOpenHeight)! + contentHeight + (isiPhoneX() ? 34 : 0)
            let height = (kSCREEN_HEIGHT - (config?.viewHeight)!)
            selectView.frame = CGRect(x: 0, y:height, width: kSCREEN_WIDTH, height: (config?.viewHeight)!)
            
        }else {
            config?.viewHeight = config?.style == .selectionStyle ? config?.filterHeight : (config?.leverFliterHeight)! + (isiPhoneX() ? 34 : 0)
            let height = (kSCREEN_HEIGHT - (config?.viewHeight)!)
            selectView.frame = CGRect(x: 0, y:height, width: kSCREEN_WIDTH, height: (config?.viewHeight)!)
        }
    }
}
